<div style="padding:20px;">
<? $defaultBespinOptions = ', "settings": {"fontsize": 10, "tabstop": 4, "theme": "white", "codecomplete": true, "autoindent": true}, "stealFocus": true'; ?>
<form id="hformt<?=(int)$arr_param["tag"]["tag_id"]?>" method="post" action="?event=builder:listModules" onsubmit="$('hCodet<?=(int)$arr_param["tag"]["tag_id"]?>').value=phpEditort<?=(int)$arr_param["tag"]["tag_id"]?>.getCode();invoke(null, 'builder:editTag&check=1', this.serialize(), true, function(req) {loadURL('?event=builder:listModules');});return false;">
	<label for="name">Name of Tag</label><br/>
	<input type="text" id="tag_name_#tag.tag_id" name="tag[name]" value="#tag.name" /><br/><br/>

	<label for="codet<?=(int)$arr_param["tag"]["tag_id"]?>">Tag Code:</label><br/>
	<input type="hidden" id="hCodet<?=(int)$arr_param["tag"]["tag_id"]?>" name="tag[html_code]" value="" />
	<textarea id="codett<?=(int)$arr_param['tag']['tag_id']?>" style="display: none;"><?=$arr_param["tag"]["html_code"]?></textarea>
	<!--[noeval]-->
	<div style="border:1px solid #ccc;" onload="(function(e){Builder.setCode('codet<?=(int)$arr_param["tag"]["tag_id"]?>', $('codett<?=(int)$arr_param['tag']['tag_id']?>').value);})" rel="builder:editTag&refresh=html_code&tag_id=<?=(int)$arr_param["tag"]["tag_id"]?>" id="codet<?=(int)$arr_param["tag"]["tag_id"]?>" data-bespinoptions='{"syntax": "html-php"<?=$defaultBespinOptions?>}'><?=$arr_param['tag']['html_code']?></div>
	<!--[/noeval]-->
	<div style="clear:both;"></div>
	<br/>
	<script type="text/javascript">
	//<![CDATA[
		setTimeout(function() {
			$('hformt<?=(int)$arr_param["tag"]["tag_id"]?>').save = function() {
				document.title = "Saving tag "+$("tag_name_#tag.tag_id").value+"...";
				$('hCodet<?=(int)$arr_param["tag"]["tag_id"]?>').value=Builder.getCode('codet<?=(int)$arr_param["tag"]["tag_id"]?>');
				invoke(null, 'builder:editTag&check=1&tag_id=<?=(int)$arr_param['tag']['tag_id']?>', $('hformt<?=(int)$arr_param["tag"]["tag_id"]?>').serialize(), true, function(req) {
					document.title = "Prails Home";
					Ext.ux.util.msg("Saving completed.", "Your changes have been saved successfully.");
					
					$('codet<?=(int)$arr_param["tag"]["tag_id"]?>').crc.content = Builder.getCode('codet<?=(int)$arr_param["tag"]["tag_id"]?>');
					$('codet<?=(int)$arr_param["tag"]["tag_id"]?>').dirty = false;
					
					if (<?=(int)$arr_param["tag"]["tag_id"]?> == 0) {
						var name = $("tag_name_#tag.tag_id").getValue();
						var id = req.responseText.split(/\s/g)[0];
						Builder.closeTab("t_0");
						var n = new Ext.tree.TreeNode({
							text: name,
							leaf: true,
							id: "t_"+id,
							allowChildren: false
						});
						Builder.tagRoot.appendChild(n);
						Builder.editTag(n);
					}
				});
				return false;			
			};
	    	
			Builder.applyBespin('codet<?=(int)$arr_param["tag"]["tag_id"]?>', function(fr) {
				$("codet<?=(int)$arr_param['tag']['tag_id']?>").down("iframe").up().style.height = (parseInt($("hformt<?=(int)$arr_param['tag']['tag_id']?>").parentNode.parentNode.style.height) - 150) + "px";
				fr.txt.addKeywords(null, function(txt) {
        			var res = [];
        			var matches = txt.getCode().match(/\$[a-zA-Z_][a-zA-Z_0-9]*\b/gi);
        			if (matches) {
	        			for (var a = 0; a < matches.length; a++) {
	        				if ((",$_GET,$_POST,$_REQUEST,$_COOKIE,$_SERVER,"+res.join(",")+",").indexOf(matches[a]) < 0) {
	        					res.push(matches[a]);
	        				}
	        			}
        			}
        			return res;
        		});
				fr.txt.addKeywords("\\$this->", ["makeVar($var)"]);
				fr.txt.addKeywords("\\$tag\\[\"", ["attributes", "body"]);
				fr.txt.addKeywords("\\$tag\\['", ["attributes", "body"]);
	          	fr.txt.addKeywords("Generator::", ["getInstance()"]);
	          	fr.txt.addKeywords("Generator::getInstance\\(\\)->", ["getTitle()", "setTitle(\"New Title\")", "getDescription()", "setDescription($description)", "setIsAjax(true)", "setKeywords($keywords)", "addHeader(\"<meta name='robots' content='index, follow' />\")", "getLanguage()"]);
	          	fr.txt.addKeywords("Generator::getInstance\\(\\)->getLanguage\\(\\)->", ["getText($identifier)", "selectTextByIdentifier($itentifier)", "listAllTextsFromRoot($rootIdentifier)", "findTextByContent($searchString)", "getAllTextsByIdentifier($identifier)"]);
	          	fr.txt.addKeywords(null, ["$tag", "$_SERVER", "$_COOKIE", "$_REQUEST", "$_GET", "$_POST", "invoke($event, $arr_param)", "checkFields($arr_toCheck, $arr_keys)", "Generator", "scaleEmbed($embed, $width, $height)", "isEmbed($embed)", "isExternalURL($string)", "if_set($a, $b)", "set_var($a, $b)", "getUserLanguage($arr_allowedLanguages, $defaultLanguage)", "wordCut($text, 200, \"...\")", "removeDir($path, true)", "hyperlink($text)", "timeDiff($time)", "toUTF8($string)", "jumpTo($url)", "createThumbnail($src, $dest, 64, 64)", "getThumbnailFromEmbed($embed)", "sendMail($to, $subject, $content, $fromName, $fromAddress)", "doGet($url)", "doPost($url, $postData)", "array_merge_recursive_distinct($arr1, $arr2)", "one_of($a, $b, ...)", "receiveFile($fileName, $targetPath)"]);
			}, Object.extend(Builder.prailsNamespace, {
	          save: function() {
	            parent.$('hformt<?=(int)$arr_param["tag"]["tag_id"]?>').save();
	          }
	      	}));

			Ext.getCmp("portlet_content_t_<?=(int)$arr_param['tag']['tag_id']?>").getTopToolbar().add([{
				xtype: "button",
				text: "Save",
				iconCls: "save",
				handler: function(e) {
					$('hformt<?=(int)$arr_param["tag"]["tag_id"]?>').save();
				}
			},"-"]);
			Ext.getCmp("portlet_content_t_<?=(int)$arr_param['tag']['tag_id']?>").getTopToolbar().doLayout();
		}, 100);
	//]]>
	</script>
</form>
</div>